const request = require('@/utils/request.js')
const constants = require('@/utils/khyConstants.js')

Component({
    lifetimes: {

    },
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        userType: '3',
        autoplay: true,
        indicatorDots: true,
        swipeList: [], //轮播图数据
        notice: getApp().globalData.nginxIp + '/img/notice.png', //通知按钮
        home_img1: getApp().globalData.nginxIp + '/img/home_menu1.png', //客运班车图标
        home_img2: getApp().globalData.nginxIp + '/img/home_menu2.png', //车站位置
        home_img3: getApp().globalData.nginxIp + '/img/home_menu3.png', //托运资费
        home_img4: getApp().globalData.nginxIp + '/img/home_menu4.png', //咨询及监督
        tuoyun: getApp().globalData.nginxIp + '/img/tuoyun.png', //托运图标
        order_button: getApp().globalData.nginxIp + '/img/order_button.png', //通用按钮背景
        home_handle_1: getApp().globalData.nginxIp + '/img/home_handle_1.png', //理货员寄件图标
        home_handle_2: getApp().globalData.nginxIp + '/img/home_handle_2.png', //理货员发货图标
        home_handle_3: getApp().globalData.nginxIp + '/img/home_handle_3.png', //理货员收货图标
        home_handle_4: getApp().globalData.nginxIp + '/img/home_handle_4.png', //用户签收确认图标
        marquee: {
            speed: 60,
            loop: -1,
            delay: 0,
        },
        changeName: '',
        noticeList: [{
            noticeTitle: '城乡公交带货进村!包头客货邮融合成乡村振兴新引擎…'
        }]
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onLoad: function () {
            const app = getApp();
            this.setData({
              swipeList: [{
                    bannerImg: app.globalData.nginxIp + '/img/test.png'
                }, {
                    bannerImg: app.globalData.nginxIp + '/img/test.png'
              }],
                //noticeList: noticeList
            })
    
        },
        /**
         * 生命周期函数--监听页面显示
         */
        onShow() {
          const app = getApp();
          this.getPageData()
          let userInfo = app.getUserInfo()
          let type = '3'
          if (userInfo && userInfo.empPost) {
            type = userInfo.empPost
          }
          this.setData({
            userType: type,
          })
          if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({
              tabvalue: 0
            })
          }
        },

        getPageData() {
            const app = getApp();
            request.get('/HomeController/getHomeData').then(res => {
                if (res.data.code == constants.resultSuccessCode &&
                    res.data.result) {
                    let bannerList = res.data.result[constants.home_bannerKey] || []
                    if(bannerList.length>0){
                        bannerList.forEach((item)=>{
                            item.bannerImg=app.globalData.nginxIp+"/"+item.bannerImg
                        })
                    }
                    let noticeList = res.data.result[constants.home_noticeKey] || []
                    this.setData({
                        swipeList: bannerList,
                        noticeList: noticeList
                    })
                }
            })
        },
        
        bannerdetail(e) {
            let bannerId = e.currentTarget.dataset.banner
            if (bannerId) {
                for (let i = 0, n = this.data.swipeList.length; i < n; i++) {
                    const element = this.data.swipeList[i];
                    if (element['keyId'] == bannerId) {
                        getApp().globalData.pageData[constants.page_bannerdetail] = element
                        wx.navigateTo({
                            url: '/pages/detail/bannerdetail/bannerdetail',
                        })

                    }
                }
            }
        },
        //公告详情
        textdetail(e) {
            let notice = e.currentTarget.dataset.notice
            getApp().globalData.pageData[constants.page_textdetail] = notice
            wx.navigateTo({
                url: '/pages/detail/textdetail/textdetail',
            })
        },
        //公告更多
        detaillist() {
            wx.navigateTo({
                url: '/pages/detail/detaillist/detaillist',
            })
        },
        //大众寄件
        orderSubmit() {
            // 大众寄件进行登录注册
            const app = getApp();
            let userInfo = app.getUserInfo()
            if (userInfo && userInfo.userNo) {
              getApp().globalData.pageData[constants.order_address] = {}
              getApp().globalData.pageData[constants.page_order] = {
                orderType: '1'
              }
              wx.navigateTo({
                url: '/pages/order/order',
              })
              
            }else {
              wx.navigateTo({
                url: '/pages/index/index',
              })
            }
        },
        //理货员寄件
        empOrderSubmit() {
          const app = getApp();
          let userInfo = app.getUserInfo()
          if (userInfo && userInfo.userNo) {
            getApp().globalData.pageData[constants.order_address] = {}
            getApp().globalData.pageData[constants.page_order] = {
                orderType: '2'
            }
            wx.navigateTo({
                url: '/pages/order/order',
            })
          } else {
            wx.navigateTo({
              url: '/pages/index/index',
            })
          }
            
        },
        skipstation() {
            wx.navigateTo({
                url: '/pages/detail/station/station',
            })
        },
        print() {
            wx.navigateTo({
                url: '/pages/print/print',
            })
        },

        tuoyunClick() {
            wx.navigateTo({
                url: '/pages/detail/tuoyun/tuoyun',
            })
        },
        zixunjianduClick() {
            wx.navigateTo({
                url: '/pages/detail/zixunjiandu/zixunjiandu',
            })
        },
        tuoyunRuleClick() {
            wx.navigateTo({
                url: '/pages/detail/tuoyunRule/tuoyunRule',
            })
        },
        baojiaRuleClick() {
            wx.navigateTo({
                url: '/pages/detail/baojiaRule/baojiaRule',
            })
        },

        station() {
            wx.navigateTo({
                url: '/pages/detail/station/station',
            })
        },
        linelist() {
            wx.navigateTo({
                url: '/pages/detail/bus/buslist/buslist',
            })
        },
        collect() {
            wx.navigateTo({
                url: '/pages/driver/collect/collect',
            })
        },
        ordergoods() {
          const app = getApp();
          let userInfo = app.getUserInfo()
          if (userInfo && userInfo.userNo) {
            wx.navigateTo({
              url: '/pages/waiter/ordergoods/ordergoods',
            })
          } else {
            wx.navigateTo({
              url: '/pages/index/index',
            })
          }
            
        },
        sendout() {
          const app = getApp();
          let userInfo = app.getUserInfo()
          if (userInfo && userInfo.userNo) {
            getApp().globalData.pageData[constants.page_sendout] = {}
            wx.navigateTo({
                url: '/pages/waiter/sendout/sendout',
            })
          } else {
            wx.navigateTo({
              url: '/pages/index/index',
            })
          }
            
        },
        delivery() {
            wx.navigateTo({
                url: '/pages/waiter/delivery/delivery',
            })
        },
        //司机揽件
        drivercheck() {
          const app = getApp();
          let userInfo = app.getUserInfo()
          if (userInfo && userInfo.userNo) {
            wx.navigateTo({
              url: '/pages/driver/collectsearch/collectsearch',
            })
          } else {
            wx.navigateTo({
              url: '/pages/index/index',
            })
          }
            
        },
        //理货员收货
        ordercheck() {
          const app = getApp();
          let userInfo = app.getUserInfo()
          if (userInfo && userInfo.userNo) {
            wx.navigateTo({
              url: '/pages/waiter/ordercheck/ordercheck',
            })
          } else {
            wx.navigateTo({
              url: '/pages/index/index',
            })
          }
            
        },

        //用户签收
        usercheck() {
          const app = getApp();
          let userInfo = app.getUserInfo()
          if (userInfo && userInfo.userNo) {
            wx.navigateTo({
              url: '/pages/waiter/usercheck/usercheck',
            })
          } else {
            wx.navigateTo({
              url: '/pages/index/index',
            })
          }
        },

        changeName() {
            if (parseInt(this.data.userType) < 3) {
                let value = parseInt(this.data.userType) + 1
                this.setData({
                    userType: value + ""
                })
            } else {
                this.setData({
                    userType: "1"
                })
            }
        }

    }
})